package juc.utils;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author 夏焰波
 * @date 2020-06-24 0:42
 */
public class CountDownLatchExample4 {
    public static void main(String[] args) throws InterruptedException {
        //参数为0则await时立即返回，参数不能为负数
        final CountDownLatch latch = new CountDownLatch(1);
        final Thread mainThread = Thread.currentThread();

        new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep(4000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                latch.countDown();
                //mainThread.interrupt();
            }
        }.start();

        //latch.await();
        latch.await(1000, TimeUnit.MILLISECONDS);
        System.out.println("===");
    }
}
